<?php

/**
 * VehiculoVenta filter form base class.
 *
 * @package    toyomotor
 * @subpackage filter
 * @author     Ing. Roberto Hernández De La Luz at Netosfera
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BaseVehiculoVentaFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'modelo'              => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'descripcion'         => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'descripcion_resumen' => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'id_ano_modelo'       => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('AnoModelo'), 'add_empty' => true)),
      'status'              => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'in_menu'             => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'foto1'               => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'foto2'               => new sfWidgetFormFilterInput(),
      'foto3'               => new sfWidgetFormFilterInput(),
      'foto4'               => new sfWidgetFormFilterInput(),
      'foto5'               => new sfWidgetFormFilterInput(),
      'foto6'               => new sfWidgetFormFilterInput(),
      'foto7'               => new sfWidgetFormFilterInput(),
      'archivo'             => new sfWidgetFormFilterInput(),
      'created_at'          => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'colores_list'        => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Color')),
    ));

    $this->setValidators(array(
      'modelo'              => new sfValidatorPass(array('required' => false)),
      'descripcion'         => new sfValidatorPass(array('required' => false)),
      'descripcion_resumen' => new sfValidatorPass(array('required' => false)),
      'id_ano_modelo'       => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('AnoModelo'), 'column' => 'id_ano_modelo')),
      'status'              => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'in_menu'             => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'foto1'               => new sfValidatorPass(array('required' => false)),
      'foto2'               => new sfValidatorPass(array('required' => false)),
      'foto3'               => new sfValidatorPass(array('required' => false)),
      'foto4'               => new sfValidatorPass(array('required' => false)),
      'foto5'               => new sfValidatorPass(array('required' => false)),
      'foto6'               => new sfValidatorPass(array('required' => false)),
      'foto7'               => new sfValidatorPass(array('required' => false)),
      'archivo'             => new sfValidatorPass(array('required' => false)),
      'created_at'          => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'colores_list'        => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Color', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('vehiculo_venta_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addColoresListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.ColoresVehiculo ColoresVehiculo')
      ->andWhereIn('ColoresVehiculo.id_color', $values)
    ;
  }

  public function getModelName()
  {
    return 'VehiculoVenta';
  }

  public function getFields()
  {
    return array(
      'id_vehiculo_venta'   => 'Number',
      'modelo'              => 'Text',
      'descripcion'         => 'Text',
      'descripcion_resumen' => 'Text',
      'id_ano_modelo'       => 'ForeignKey',
      'status'              => 'Boolean',
      'in_menu'             => 'Boolean',
      'foto1'               => 'Text',
      'foto2'               => 'Text',
      'foto3'               => 'Text',
      'foto4'               => 'Text',
      'foto5'               => 'Text',
      'foto6'               => 'Text',
      'foto7'               => 'Text',
      'archivo'             => 'Text',
      'created_at'          => 'Date',
      'colores_list'        => 'ManyKey',
    );
  }
}
